package com.example.tao.smartcar;

import android.app.Activity;
import android.app.Application;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by Tao on 2016/7/30.
 */
public class SmartCarApplication extends Application {
    public static final Boolean DEBUG = true;

    private List<Activity> activities = null;

    private static SmartCarApplication instance;


    public SmartCarApplication() {
        activities = new LinkedList<>();
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
    }

    public static SmartCarApplication getInstance() {
        if (instance == null) {
            instance = new SmartCarApplication();
        }
        return instance;
    }

    public void addActivity(Activity activity) {
        if (activities != null && activities.size() > 0) {
            if (!activities.contains(activity)) {
                activities.add(activity);
            }
        } else {
            activities.add(activity);
        }
    }

    public void exit() {
        if (activities != null && activities.size() > 0) {
            for (Activity activity : activities) {
                activity.finish();
            }
        }
    }
}
